﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ninject;

namespace FiveInRow
{
    class Factory
    {
        Ninject.IKernel kernel;

        public Factory()
        {
            kernel = new StandardKernel();

            kernel.Bind<IPiece>().To<Entity.Piece>();
            kernel.Bind<IChessStatus>().To<Entity.ChessStatus>();
            kernel.Bind<IStrategy>().To<UnManagedWrapper.StrategyWrapper>();
        }

        public IPiece CreatePiece(Dictionary<string,object> param)
        {
            return kernel.Get<IPiece>(ToArgs(param));
        }

        public IChessStatus CreateChessStatus(Dictionary<string, object> param)
        {
            return kernel.Get<IChessStatus>(ToArgs(param));
        }

        public IStrategy CreateStrategy(Dictionary<string, object> param)
        {
            return kernel.Get<IStrategy>(ToArgs(param));
        }

        private Ninject.Parameters.ConstructorArgument[] ToArgs(Dictionary<string, object> param)
        {
            List<Ninject.Parameters.ConstructorArgument> arg = new List<Ninject.Parameters.ConstructorArgument>();
            foreach (var pair in param)
            {
                arg.Add(new Ninject.Parameters.ConstructorArgument(pair.Key, pair.Value));
            }

            return arg.ToArray();
        }
    }
}
